package com.zxp.spi.service;

import sun.misc.Service;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * @author zxp
 * @date 2021-08-23 11:45
 */
public class SpiMain {
    public static void main(String[] args) {

        Iterator<HelloSpiService> providers = Service.providers(HelloSpiService.class);
        ServiceLoader<HelloSpiService> load = ServiceLoader.load(HelloSpiService.class);

        while(providers.hasNext()) {
            HelloSpiService ser = providers.next();
            ser.execute("zxp");
        }
        System.out.println("--------------------------------");
        Iterator<HelloSpiService> iterator = load.iterator();
        while(iterator.hasNext()) {
            HelloSpiService ser = iterator.next();
            ser.execute("xcx");
        }
    }
}
